Skip to content

Sheffield | 26-ITP-jan | Richard Frimpong | Sprint 3 | Stretch Coursework#1250

Open
Richiealx wants to merge 2 commits intoCodeYourFuture:mainfrom
Richiealx:coursework/sprint-3-stretch-redo
Open

Sheffield | 26-ITP-jan | Richard Frimpong | Sprint 3 | Stretch Coursework#1250
Richiealx wants to merge 2 commits intoCodeYourFuture:mainfrom
Richiealx:coursework/sprint-3-stretch-redo

Conversation

@Richiealx
Copy link

@Richiealx Richiealx commented Mar 12, 2026

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Completed the Sprint 3 stretch tasks.

Password Validator

  • Implemented password validation rules in password-validator.js
  • Added Jest tests in password-validator.test.js

Credit Card Validator

  • Implemented credit card validation logic in card-validator.js
  • Added Jest tests in card-validator.test.js

Testing

All tests were run using:

All tests passed successfully.

@Richiealx Richiealx added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 12, 2026
return password.length < 5 ? false : true
}
// Password must be at least 5 characters long.
if (password.length < 5) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could password just not be provided at all?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ykamal,

Good point, thank you.

I updated the function to handle the case where a password is not provided.
Previously the function accessed password.length, which would throw an error if the value was undefined.

I added an input validation check at the start of the function to ensure the password exists and is a string. If it is missing or not a string, the function now safely returns false.

I also added test cases to cover these scenarios.

@ykamal ykamal added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 12, 2026
@Richiealx Richiealx added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 12, 2026
@@ -0,0 +1,33 @@
// Validate whether a credit card number meets the rules from card-validator.md
function validateCreditCardNumber(cardNumber) {
// Rule 1: the value must be exactly 16 characters long and contain only digits.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing down these rules as comments in code is very helpful for making sure you complete all of them and also helpful for debugging in plain english. good job

@@ -0,0 +1,33 @@
// Validate whether a credit card number meets the rules from card-validator.md
function validateCreditCardNumber(cardNumber) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is more of an advanced thing, but as a general rule if you're implementing a function that returns a boolean (true/false) its best to start the function name with "is" or "has" to make it clear to a reader that it returns a boolean. So this one could be called "isCreditCardNumberValid" for example

Comment on lines +21 to +28
let sum = 0;
for (const digit of cardNumber) {
sum += Number(digit);
}

if (sum <= 16) {
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this works, it is slightly inefficient as it requires you to loop through the entire list of digits before saying true/false even if the first 4 3 digits are more than 16 for example. Can you think of a way to make this more efficient and return earlier?

@kyle-tightest kyle-tightest removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants